<template>
  <CommonCard title="累计用户数" :value="numberFormat(userToal)">

    <div ref="barChartRef" style="width: 100%;height: 100%;"></div>

    <template #foot>
      <div class="footer">
        <span>日同比</span>
        <span class="emphasis">{{userGrowthLastDay}}%</span>
        <span class="increment"></span>
        <span style="margin-left:10px">月同比</span>
        <span class="emphasis">{{userGrowthLastMonth}}%</span>
        <span class="decrement"></span>
      </div>

    </template>
  </CommonCard>
</template>

<script lang="ts">
import CommonCard from './CommonCard.vue'
export default {
  name: 'TatalUser',
  components: {
    CommonCard
}
}
</script>

<script lang="ts" setup>
import { ref, onMounted,computed } from 'vue'
import * as echarts from 'echarts'
import type { EChartsType } from 'echarts'
import { useReportDataStore } from '@/stores/reportData'
import useFormat from '@/hooks/useFormat'
const reportDataStore = useReportDataStore()
const { numberFormat, moneyFormat } = useFormat()

// 定义变量
const barChartRef = ref()
let myChart: EChartsType
let ranChart = Math.random() * 100

// 累计用户数
const userToal = computed(()=>reportDataStore.reportData.usersTotal)
const usersLastMonth = computed(()=>reportDataStore.reportData.usersLastMonth)
const userGrowthLastDay = computed(()=>reportDataStore.reportData.userGrowthLastDay)
const userGrowthLastMonth = computed(() => reportDataStore.reportData.userGrowthLastMonth)

const getOption = () => {
  return {
    grid: {
      left: 0,
      right: 0
    },
    xAxis: {
      min: 0,
      max: 100,
      show: false
    },
    yAxis: {
      show: false,
      // 将X轴的数据项给到Y轴，从而让柱条以水平方向和呈现
      data: ['数据']
    },
    series: {
      type: 'bar',
      data:[ranChart],
      // 设置柱条的宽度
      barWidth: 10,
      // 显示柱条的背景颜色
      showBackground: true,
      itemStyle: {
        color: 'orangered'
      },
      // 设置刻度样式
      label: {
        show: true,
        // 把文字改成竖线
        formatter: '|',
        color: 'orangered',
        position: 'right'
      },
      // 显示提示
     tooltip: {
      trigger: 'axis',
      confine: true
    }
    }
  }
}

// 组件挂载完毕就要显示图形
onMounted(() => {
  myChart = echarts.init(barChartRef.value)
  myChart.setOption(getOption())
})
</script>

<style lang="scss" scoped>
.footer {
  display: flex;
  // flex:1;
  align-items: center;
}
</style>